package com.atstudent.gmall.common.exception;

import com.atstudent.gmall.common.execption.GmallException;
import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.common.result.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName：GlobalExceptionHandler
 * @Dexcription
 * @Author 薛有朋
 * @CreatDate 2024/11/21 20:33
 **/
@RestControllerAdvice //声明当前类就是一个全局异常处理器
public class GlobalExceptionHandler {

    /*
     * @Description 处理自定义异常
     * @Author 薛有朋
     * @Date 2024/11/21 20:34
     **/
    @ExceptionHandler(value = GmallException.class)
    public Result gmallExceptionHandler(GmallException e){
        e.printStackTrace();
        return Result.build(null , e.getResultCodeEnum());
    }


    /*
     * @Description 处理其他异常
     * @Author 薛有朋
     * @Date 2024/11/21 20:34
     **/
    @ExceptionHandler(value = Exception.class)
    public Result systemExceptionHandler(Exception e){
        e.printStackTrace();
        return Result.build(null , ResultCodeEnum.SYS_ERROR);
    }
}
